<?php

namespace App\Admin\Controllers;

use App\Models\StoreModel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class StoreController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '门店表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new StoreModel());

        $grid->column('id', __('Id'));
        $grid->column('store_name','门店名称');
        $grid->column('phone','联系电话');
        $grid->column('nickName','昵称');
        $grid->column('head_img','头像')->image('',160,160);
        $grid->column('balance','余额');
        //$grid->column('balance','余额');
      /*  $grid->column('
        authentication_data', __('
        authentication data'));*/

        $grid->column('status','状态')->using(['1' =>'正常','2' =>'封停'])->label([
            1 => 'success',
            2 => 'warning'
        ]);
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(StoreModel::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('store_name','门店名称');
        $show->field('phone','手机');
        $show->field('nickName','昵称');
        $show->field('head_img','头像')->image('',100,100);
        $show->field('balance','余额');
        /*$show->field('
        authentication_data', __('
        authentication data'));*/
        $show->field('status','状态')->using([1 => '正常',2 => '封停']);
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new StoreModel());

        $form->text('store_name','门店名称');
        $form->number('phone','电话号码');
        $form->text('nickName','昵称');
        //$form->password('nickName','密码');
        $form->image('head_img','门店头像')->move('images/' . date('Ymd')) -> uniqueName();
        //$form->decimal('balance','月')->default(0.00);
        /*$form->textarea('
        authentication_data', __('
        authentication data'));*/
        $form->switch('status','门店状态')->options([1 => '正常',2 => '封停'])->default(1);

        return $form;
    }
}
